/////////////////////////////////////////////////////////
//                                                     //
// Copyright (c) 2016年 上证云平台. All rights reserved. //
//                                                     //
/////////////////////////////////////////////////////////

#import "TCPQuoteViewController.h"
#import "NSObject+Description.h"

#ifdef __MAPI_TCP_ENABLED

@interface TCPQuoteViewController ()<UITextFieldDelegate>
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UIButton *buttonForLevel1;
@property (nonatomic, strong) UIButton *buttonForLevel2;
@property (nonatomic, strong) UITextField *textInPut1;
@property (nonatomic, strong) UIButton *buttonSubscribe;
@property (nonatomic, strong) UITextField *textInPut2;
@property (nonatomic, strong) UIButton *buttonUnSubscribe;
@property (nonatomic, strong) UIButton *buttonUnSubscribeAllFromType;
@property (nonatomic, strong) UIButton *buttonUnSubscribeAll;
@property (nonatomic, strong) UITextField *textInPut3;
@property (nonatomic, strong) UIButton *buttonSubscribeType;
@property (nonatomic, strong) MStockItem *stockItem;
//@property (nonatomic, strong) NSString *str;
@end

@implementation TCPQuoteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _textView = [[UITextView alloc] initWithFrame:self.view.bounds];
    
    _buttonForLevel1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonForLevel1 setTitle:@"L1" forState:UIControlStateNormal];
    _buttonForLevel1.frame=CGRectMake(0, 0, 30, 30);
    [_buttonForLevel1 addTarget:self action:@selector(level1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonForLevel1];
    
    _buttonForLevel2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonForLevel2 setTitle:@"L2" forState:UIControlStateNormal];
    _buttonForLevel2.frame=CGRectMake(30, 0, 30, 30);
    [_buttonForLevel2 addTarget:self action:@selector(level2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonForLevel2];
    
    _textInPut3 = [[UITextField alloc] initWithFrame:CGRectMake(10, 30, [UIScreen mainScreen].bounds.size.width*2/3-10, 30)];
    _textInPut3.borderStyle = UITextBorderStyleLine;
    _textInPut3.delegate = self;
    _textInPut3.placeholder = @"请输入订阅类型，用,隔开";
//    _textInPut3.text = @"1";
    _textInPut3.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:_textInPut3];
    
    _buttonSubscribe = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonSubscribe setTitle:@"设置订阅类型" forState:UIControlStateNormal];
    _buttonSubscribe.frame=CGRectMake([UIScreen mainScreen].bounds.size.width*2/3, 25, 100, 40);
    [_buttonSubscribe addTarget:self action:@selector(subscribeType) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonSubscribe];
    
    _textInPut1 = [[UITextField alloc] initWithFrame:CGRectMake(10, 70, [UIScreen mainScreen].bounds.size.width*5/6-20, 30)];
    _textInPut1.borderStyle = UITextBorderStyleLine;
    _textInPut1.delegate = self;
    _textInPut1.placeholder = @"请输入需要订阅的股票代码，用,隔开";
    _textInPut1.text = @"600000.sh";
    _textInPut1.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:_textInPut1];
    
    _buttonSubscribe = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonSubscribe setTitle:@"订阅" forState:UIControlStateNormal];
    _buttonSubscribe.frame=CGRectMake([UIScreen mainScreen].bounds.size.width*5/6-10, 70, 40, 30);
    [_buttonSubscribe addTarget:self action:@selector(subscribe) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonSubscribe];
    
    _textInPut2 = [[UITextField alloc] initWithFrame:CGRectMake(10, 110, [UIScreen mainScreen].bounds.size.width-20, 30)];
    _textInPut2.borderStyle = UITextBorderStyleLine;
    _textInPut2.delegate = self;
    _textInPut2.placeholder = @"请输入需要取消订阅的股票代码，用,隔开";
    _textInPut2.text = @"600000.sh";
    _textInPut2.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:_textInPut2];
    
    _buttonUnSubscribe = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonUnSubscribe setTitle:@"取消订阅" forState:UIControlStateNormal];
    _buttonUnSubscribe.frame=CGRectMake(0, 140, 80, 40);
    [_buttonUnSubscribe addTarget:self action:@selector(unSubscribe) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonUnSubscribe];
    
    _buttonUnSubscribeAllFromType = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonUnSubscribeAllFromType setTitle:@"取消当前类型所有订阅" forState:UIControlStateNormal];
    _buttonUnSubscribeAllFromType.frame=CGRectMake(80, 140, 200, 40);
    [_buttonUnSubscribeAllFromType addTarget:self action:@selector(unSubscribeAllFromType) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonUnSubscribeAllFromType];
    
    _buttonUnSubscribeAll = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_buttonUnSubscribeAll setTitle:@"取消所有订阅" forState:UIControlStateNormal];
    _buttonUnSubscribeAll.frame=CGRectMake(280, 140, 120, 40);
    [_buttonUnSubscribeAll addTarget:self action:@selector(unSubscribeAll) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_buttonUnSubscribeAll];
    
    _textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _textView.frame=CGRectMake(0, 170, self.view.bounds.size.width, self.view.bounds.size.height-60);
    _textView.editable = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_textView];
    [self TCP];
//    MSnapQuoteRequest *request = [[MSnapQuoteRequest alloc] init];
//    request.code = @"H50053.csi";
//    [MApi sendRequest:request completionHandler:^(MResponse *resp) {
//        MSnapQuoteResponse *response = (MSnapQuoteResponse *)resp;
//        self.stockItem = response.stockItem;
//        if (response.status == MResponseStatusSuccess) {
//            [MApi subscribeQuoteCode:@"H50053.csi" didReceiveUpdate:^(NSString *code, MApiTcpUpdateBlock update) {
//                update(self.stockItem);
//                NSDictionary *des = [self.stockItem mapi_description:self.stockItem.class];
//                NSString *str = [NSString stringWithCString:[des.description cStringUsingEncoding:NSUTF8StringEncoding] encoding:NSNonLossyASCIIStringEncoding];
//                self.textView.text = str;
//            }];
//        }
//    }];
////         练习:真行情快照
//        MSnapQuoteRequest *request = [[MSnapQuoteRequest alloc] init];
//    //
//        request.code = @"600000.sh"; //填入股票代码
//        request.tickCount = 10;//明细条数
//    //    request.stockFields = @[@"buyPrices",@"sellPrices",@"lastPrice"];
//        request.stockFields = nil;
//    ////     request.addValueFields = @[@"-1"];
//        request.addValueFields = nil;
//    
//        //发送请求
//        [MApi sendRequest:request completionHandler:^(MResponse *resp) {
//            if (resp.status == MResponseStatusSuccess) {
//                //应答无误，处理数据更新画面
//                MSnapQuoteResponse *response = (MSnapQuoteResponse *)resp;
//                MStockItem *item = response.stockItem;
//                 NSLog(@"%@",item);
//                NSLog(@"%@",request.ip);
//                BOOL bond = item.bond;
//                NSLog(@"%@",bond?@"YES":@"NO");
//            } else {
//                //应答错误，显示错误信息
//                NSLog(@"回传代码：%ld",(long)resp.status);
//                //NSLog(@"错误站点信息：%@",request.ip);
//                NSLog(@"行情快照请求错误，错误信息是：%@",resp.message);
//            }
//        }];
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
//-(void)TCP{
//    self.codes = @"600000.sh,688001.sh,300960.sz,002162.sz,00700.hk,00992.hk,830993.bj,10002888.sh,90000499.sz,IC2104.cff,b2105.dce,AP105.czce,ag2105.shfe,bc2104.ine,000801.csi,W00032.gb,CNYEUR.gb";
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeSnap];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tcpDidReceivedData:)name:MApiTcpDidReceivedDataNotification object:nil];
//}

//-(void)tcpDidReceivedData:(NSNotification *)notification {
//    NSDictionary *dic = notification.userInfo;
//    MApiTcpSubscribeType type = [dic[MApiTcpDidReceivedDataTypeKey] integerValue];
////    NSString *code = dic[MApiTcpDidReceivedDataSnapKey];
//    if (type == MApiTcpSubscribeTypeSnap) {
////        NSLog(@"============行情快照:%@",dic[MApiTcpDidReceivedDataSnapKey]);
//        MStockItem *date = dic[MApiTcpDidReceivedDataSnapKey];
////        NSLog(@"朱宝平：%@",date);
//        _textView.text = [NSString stringWithFormat:@"%@",date];
//        }
//
//}
- (void)level1{
    [MApi setSourcePermissions:@{
        MApiMarketSH:@(MApiSourceLevel1),
        MApiMarketSZ:@(MApiSourceLevel1),
        MApiMarketBJ:@(MApiSourceLevel1),
        MApiMarketHK:@(MApiSourceHK10),
        MApiMarketCFF:@(MApiSourceCFF1),
        MApiMarketDCE:@(MApiSourceDCE1),
        MApiMarketCZCE:@(MApiSourceCZCE1),
        MApiMarketSHFE:@(MApiSourceSHFE1),
        MApiMarketINE:@(MApiSourceINE1)
        }];
    NSLog(@"设置当前权限为L1!");
}
- (void)level2{
    [MApi setSourcePermissions:@{
        MApiMarketSH:@(MApiSourceLevel2),
        MApiMarketSZ:@(MApiSourceLevel2),
        MApiMarketBJ:@(MApiSourceLevel1),
        MApiMarketHK:@(MApiSourceHK10),
        MApiMarketCFF:@(MApiSourceCFF1),
        MApiMarketDCE:@(MApiSourceDCE1),
        MApiMarketCZCE:@(MApiSourceCZCE1),
        MApiMarketSHFE:@(MApiSourceSHFE1),
        MApiMarketINE:@(MApiSourceINE1)
        }];
    NSLog(@"设置当前权限为L2!");
}
- (void)subscribeType{
    _types = [_textInPut3.text componentsSeparatedByString:@","];
    NSLog(@"设置订阅类型为：%@",_types);
//    NSLog(@"``%@,%ld",_type,(unsigned long)_type.count);
}
- (void)subscribe{
    self.codes = [NSString stringWithFormat:@"%@",_textInPut1.text];
//    NSLog(@"!@##$%@",self.codes);
    [self TCP];
}
- (void)unSubscribe{
    _textView.text = @"";
    for (int i=0;i<_types.count;i++){
        [MApi unSubscribeCode:_textInPut2.text type:((NSString*)_types[i]).intValue];
    }
}
- (void)unSubscribeAllFromType{
    _textView.text = @"";
    for (int i=0;i<_types.count;i++){
        [MApi unSubscribeAllCodeType:((NSString*)_types[i]).intValue];
    }
}
- (void)unSubscribeAll{
    _textView.text = @"";
    [MApi unSubscribeAllCodeType:MApiTcpSubscribeTypeAll];
}



- (void)TCP{
    for (int i=0;i<_types.count;i++){
        [MApi subscribeCode:self.codes type:((NSString*)_types[i]).intValue];
    }
    
    
//    self.codes = @"871981.bz,833454.bz,832089.bz,300185.sz,600905.sh,00700.hk";
////  行情快照
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeSnap];

////  当日走势
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeLine];
//
////  五日走势
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeLine5];
//
////  分时明细
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeTick];
//
////  逐笔明细
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeTickDetail];
//
////  日K
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeDayK];
//
////  日K前复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeDayFK];
//
////  日K后复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeDayBK];
//
////  周K
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeWeekK];
//
////  周K前复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeWeekFK];
//
////  周K后复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeWeekBK];
//
////  月K
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeMonthK];
//
////  月K前复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeMonthFK];
//
////  月K后复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeMonthBK];
//
////  年K
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeYearK];
//
////  年K前复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeYearFK];
//
////  年K后复权
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeYearBK];
//
////  千档行情
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeThousands];
//
////  全席队列
////  订阅代码  股票代码 $ 档位价格
////  其中档位价格 为千档行情返回的原始价格
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeQX];
//
////  逐笔委托
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeTickEntrust];
//
////  逐笔还原
//    [MApi subscribeCode:self.codes type:MApiTcpSubscribeTypeL2PlusTickDetail];


    //监听
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(tcpDidReceivedData:)
                                                 name:MApiTcpDidReceivedDataNotification
                                               object:nil];
}

//监听回调数据处理
- (void)tcpDidReceivedData:(NSNotification *)notification {

    NSDictionary *dic = notification.userInfo;
    MApiTcpSubscribeType type = [dic[MApiTcpDidReceivedDataTypeKey] integerValue];
    NSString *code = dic[MApiTcpDidReceivedDataCodeKey];
    
    
    if (type == MApiTcpSubscribeTypeThousands) {
        NSLog(@"============千档行情:");
        MThousandsData *date = dic[MApiTcpDidReceivedDataThousandsKey];
        [MApi subscribeCode:[NSString stringWithFormat:@"%@$%@",code,date.buyItems.firstObject.originalPrice] type:MApiTcpSubscribeTypeQX];
        _textView.text = [NSString stringWithFormat:@"买：%@\n卖：%@\n%@",date.buyItems.firstObject,date.sellItems.firstObject,_textView.text];
        NSLog(@"买：%@",date.buyItems.firstObject);
//        NSLog(@"卖：%@",date.sellItems.firstObject);
    }
    else if (type == MApiTcpSubscribeTypeQX) {
    NSLog(@"============全席队列:%@",dic[MApiTcpDidReceivedDataQXKey]);
        MQXData *item = dic[MApiTcpDidReceivedDataQXKey];
        _textView.text = [NSString stringWithFormat:@"%@\n%@\n%@",item.price,item.volumes,_textView.text];
        NSLog(@"%@",item.price);
        NSLog(@"%@",item.volumes);
    }
    else if (type == MApiTcpSubscribeTypeTickEntrust) {
        NSLog(@"============逐笔委托:%@",dic[MApiTcpDidReceivedDataTickEntrustKey]);
        NSArray <MTickEntrustItem *> *array = dic[MApiTcpDidReceivedDataTickEntrustKey];
        [array enumerateObjectsUsingBlock:^(MTickEntrustItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            //        字段说明: sn=委托序号,p=委托价,q=委托量,bs=买卖方,o=委托型态,t=委托时间
            NSLog(@"%@ : %@ : %@ : %@ : %@",obj.time,obj.sn,obj.price,obj.volume,obj.bs);
        }];
        _textView.text = array.lastObject.time;
    }
    else if (type == MApiTcpSubscribeTypeL2PlusTickDetail) {
    NSLog(@"============逐笔还原:%@",dic[MApiTcpDidReceivedDataL2PlusTimeTickDetailKey]);
        NSArray <MTimeTickDetailItem *> *array = dic[MApiTcpDidReceivedDataL2PlusTimeTickDetailKey];
        [array enumerateObjectsUsingBlock:^(MTimeTickDetailItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"买委托序号:%@  卖委托序号:%@ 买委托量:%@ 卖委托量:%@",obj.bn,obj.on,obj.bq,obj.oq);
        }];
        _textView.text = [NSString stringWithFormat:@"%@",dic[MApiTcpDidReceivedDataL2PlusTimeTickDetailKey]];
    }
    else if (type == MApiTcpSubscribeTypeSnap){
        NSLog(@"%@============行情快照:%@",code,dic[MApiTcpDidReceivedDataSnapKey]);
            MStockItem *date = dic[MApiTcpDidReceivedDataSnapKey];
        //        NSLog(@"朱宝平：%@",date);
            _textView.text = [NSString stringWithFormat:@"%@",date.datetime];
        

    }
    else if (type == MApiTcpSubscribeTypeLine|type == MApiTcpSubscribeTypeLine5){
        NSArray <MOHLCItem*>*date = dic[MApiTcpDidReceivedDataLineItemsKey];
        NSArray <MOHLCItem*>*date1 = dic[MApiTcpDidReceivedDataAFItemsKey];
        NSLog(@"%@============走势中的行情快照:%@",code,dic[MApiTcpDidReceivedDataSnapKey]);
        [date enumerateObjectsUsingBlock:^(MOHLCItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
            if (type == MApiTcpSubscribeTypeLine){
//                NSLog(@"%@============当日走势:%@",code,obj);
            }else if (type == MApiTcpSubscribeTypeLine5){
//                NSLog(@"%@============五日走势:%@",code,obj);
            }
        }];
        if (type == MApiTcpSubscribeTypeLine){
                NSLog(@"%@============当日走势:%@",code,date.lastObject);
        }else if (type == MApiTcpSubscribeTypeLine5){
                NSLog(@"%@============五日走势:%@",code,date.lastObject);
        }
        [date1 enumerateObjectsUsingBlock:^(MOHLCItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
            NSLog(@"%@============盘后走势：%@",code,obj);
        }];
        //        NSLog(@"朱宝平：%@",date);
//        _textView.text = [NSString stringWithFormat:@"%@\n%@",date,date1];
        _textView.text = date.lastObject.datetime;
//        _textView.text = [[NSString stringWithFormat:@"%@\n%@",date,date1] substringWithRange:NSMakeRange(0, 500)];
    }
    else if (type == MApiTcpSubscribeTypeTick){
        NSArray <MTickItem*> *date = dic[MApiTcpDidReceivedDataTimeTickKey];
        [date enumerateObjectsUsingBlock:^(MTickItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
            NSLog(@"%@============分时明细:%@",code,obj);
        }];
        //        NSLog(@"朱宝平：%@",date);
        _textView.text = [NSString stringWithFormat:@"%@",date.lastObject.time6];
    }
    else if (type == MApiTcpSubscribeTypeTickDetail){
        NSArray <MTimeTickDetailItem*> *date = dic[MApiTcpDidReceivedDataTimeTickDetailKey];
        [date enumerateObjectsUsingBlock:^(MTimeTickDetailItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
            NSLog(@"%@============逐笔明细:%@",code,obj);
        }];
        //        NSLog(@"朱宝平：%@",date);
        _textView.text = [NSString stringWithFormat:@"%@",date.lastObject.time6];
    }
    else if (type == MApiTcpSubscribeTypeDayK|type == MApiTcpSubscribeTypeDayFK|type == MApiTcpSubscribeTypeDayBK|type == MApiTcpSubscribeTypeWeekK|type == MApiTcpSubscribeTypeWeekFK|type == MApiTcpSubscribeTypeWeekBK|type == MApiTcpSubscribeTypeMonthK|type == MApiTcpSubscribeTypeMonthFK|type == MApiTcpSubscribeTypeMonthBK|type == MApiTcpSubscribeTypeYearK|type == MApiTcpSubscribeTypeYearFK|type == MApiTcpSubscribeTypeYearBK|type == MApiTcpSubscribeTypeQuarterK|type == MApiTcpSubscribeTypeQuarterFK|type == MApiTcpSubscribeTypeQuarterBK){
        NSArray <MOHLCItem*>*date = dic[MApiTcpDidReceivedDataKKey];
        NSArray <MOHLCItem*>*date1 = dic[MApiTcpDidReceivedDataFQKey];
        NSArray <MOHLCItem*>*date2 = dic[MApiTcpDidReceivedDataCSKey];
        [date enumerateObjectsUsingBlock:^(MOHLCItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
            NSString *obj1 = [NSString stringWithFormat:@"%@",obj];
            if (type == MApiTcpSubscribeTypeDayK){
                NSLog(@"%@============日K:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeDayFK){
                NSLog(@"%@============日K前复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeDayBK){
                NSLog(@"%@============日K后复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeWeekK){
                NSLog(@"%@============周K:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeWeekFK){
                NSLog(@"%@============周K前复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeWeekBK){
                NSLog(@"%@============周K后复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeMonthK){
                NSLog(@"%@============月K:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeMonthFK){
                NSLog(@"%@============月K前复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeMonthBK){
                NSLog(@"%@============月K后复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeYearK){
                NSLog(@"%@============年K:%@",code,obj1);
            }
            else if (type == MApiTcpSubscribeTypeYearFK){
                NSLog(@"%@============年K前复权:%@",code,obj1);
            }
            else if (type == MApiTcpSubscribeTypeYearBK){
                NSLog(@"%@============年K后复权:%@",code,obj1);
            }else if (type == MApiTcpSubscribeTypeQuarterK){
                NSLog(@"%@============季K:%@",code,obj1);
            }
            else if (type == MApiTcpSubscribeTypeQuarterFK){
                NSLog(@"%@============季K前复权:%@",code,obj1);
            }
            else if (type == MApiTcpSubscribeTypeQuarterBK){
                NSLog(@"%@============季K后复权:%@",code,obj1);
            }
        }];
        [date1 enumerateObjectsUsingBlock:^(MOHLCItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
//            NSLog(@"%@============复权信息:%@",code,obj);
        }];
        [date2 enumerateObjectsUsingBlock:^(MOHLCItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop){
//            NSLog(@"%@============股本数据:%@",code,obj);
        }];
        //        NSLog(@"朱宝平：%@",date);
        _textView.text = [NSString stringWithFormat:@"%@,%@,%@",date,date1,date2];
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    
    
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
//    [MApi unsubscribeAllQuoteCode];
//    [MApi unSubscribeAllCodeType:MApiTcpSubscribeTypeAll];
//    [MApi unSubscribeAllCodeType:MApiTcpSubscribeTypeLine5];
//    [MApi unSubscribeAllCodeType:MApiTcpSubscribeTypeSnap];
//     [MApi unSubscribeAllCodeType:MApiTcpSubscribeTypeDayK];
    
    [MApi unSubscribeAllCodeType:MApiTcpSubscribeTypeAll];
}


@end

#endif
